package com.pd.backend.service.impl;

import com.pd.backend.entity.QrtzTriggers;
import com.pd.backend.dao.QrtzTriggersDao;
import com.pd.backend.service.QrtzTriggersService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (QrtzTriggers)表服务实现类
 *
 * @author GuoXinChao.126@gmail.com
 * @since 2023-02-27 17:14:38
 */
@Service("qrtzTriggersService")
public class QrtzTriggersServiceImpl implements QrtzTriggersService {
    @Resource
    private QrtzTriggersDao qrtzTriggersDao;

    /**
     * 通过ID查询单条数据
     *
     * @param schedName 主键
     * @return 实例对象
     */
    @Override
    public QrtzTriggers queryById(String schedName) {
        return this.qrtzTriggersDao.queryById(schedName);
    }

    /**
     * 分页查询
     *
     * @param qrtzTriggers 筛选条件
     * @param pageRequest  分页对象
     * @return 查询结果
     */
    @Override
    public Page<QrtzTriggers> queryByPage(QrtzTriggers qrtzTriggers, PageRequest pageRequest) {
        long total = this.qrtzTriggersDao.count(qrtzTriggers);
        return new PageImpl<>(this.qrtzTriggersDao.queryAllByLimit(qrtzTriggers, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param qrtzTriggers 实例对象
     * @return 实例对象
     */
    @Override
    public QrtzTriggers insert(QrtzTriggers qrtzTriggers) {
        this.qrtzTriggersDao.insert(qrtzTriggers);
        return qrtzTriggers;
    }

    /**
     * 修改数据
     *
     * @param qrtzTriggers 实例对象
     * @return 实例对象
     */
    @Override
    public QrtzTriggers update(QrtzTriggers qrtzTriggers) {
        this.qrtzTriggersDao.update(qrtzTriggers);
        return this.queryById(qrtzTriggers.getSchedName());
    }

    /**
     * 通过主键删除数据
     *
     * @param schedName 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String schedName) {
        return this.qrtzTriggersDao.deleteById(schedName) > 0;
    }
}
